﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Kaskelot.Services.Model;

namespace Stockholm.SOA.Kaskelot.WCF.ServiceImplementation.Mapping
{
	public static class PersonHandelseLoggExtensions
	{
		public static DataContracts.PersonHandelseLogg ToContract(this PersonHandelseLogg entity)
		{
			DataContracts.PersonHandelseLogg b = new DataContracts.PersonHandelseLogg();

			CopyFromEntity(entity, b, false);

			return b;
		}

		public static DataContracts.PersonHandelseLogg ToMinimalContract(this PersonHandelseLogg entity)
		{
			DataContracts.PersonHandelseLogg b = new DataContracts.PersonHandelseLogg();

			CopyFromEntity(entity, b, true);

			return b;
		}

		public static PersonHandelseLogg ToEntity(this DataContracts.PersonHandelseLogg b)
		{
			PersonHandelseLogg entity = new PersonHandelseLogg();

			CopyToEntity(b, entity);

			return entity;
		}

        public static void UpdateEntity(this PersonHandelseLogg entity, DataContracts.PersonHandelseLogg phl)
        {
            CopyToEntity(phl, entity);
        }

		private static void CopyFromEntity(PersonHandelseLogg from, DataContracts.PersonHandelseLogg to, bool minimal)
		{
			to.Id = from.Id;
			to.ValId = from.ValId;

			to.PersonId = from.PersonId;
            to.PersonNamn = from.Person.Fornamn  + " " + from.Person.Efternamn;
			to.Text = from.Text;
			to.UppfoljningKravs = from.UppfoljningKravs;
			to.Datum = from.Datum;

			to.Andrad = from.Andrad;
			to.AndradAv = from.AndradAv;
			to.Skapad = from.Skapad;
			to.SkapadAv = from.SkapadAv;
		}

		private static void CopyToEntity(DataContracts.PersonHandelseLogg from, PersonHandelseLogg to)
		{
			to.Id = from.Id;
			to.ValId = from.ValId;

			to.PersonId = from.PersonId;
			to.Text = from.Text;
			to.UppfoljningKravs = from.UppfoljningKravs;
			to.Datum = from.Datum;

			to.Andrad = from.Andrad;
			to.AndradAv = from.AndradAv;
			to.Skapad = from.Skapad;
			to.SkapadAv = from.SkapadAv;
		}
	}
}
